package com.wwl.cms.utils.designModeTest.state;

import lombok.Data;

/**
 * @author wwl
 * @version 1.0
 * @date 2021/9/27 10:51
 * @description:
 */
@Data
public class RaffleActivity {
    State state = null;

    //奖品数量
    int count = 0;
    //四个属性表示，四种状态
    State noRafflleState = new NoRaffleState(this);
    State canRaffleState = new CanRaffleState(this);
    State dispenseState = new DispenseState(this);
    State dispensOutState = new DispenseOutState(this);
    //构造器
    //1.初始化当前的状态为noRafflleState(不能抽奖)
    //2.初始化奖品数量
    public RaffleActivity( int count) {
        this.state = getNoRafflleState();
        this.count = count;
    }
    //扣分
    public void debuctMoney(){
        state.deductMoney();
    }
    //抽奖
    public void raffle(){
        //如果当前的状态是抽奖成功
        if (state.raffle()){
            state.dispensePrize();
        }
    }

    public int getCount() {
        int curCount = count;
        count--;
        return curCount;
    }
}
